[SR-184] Better diagnose error via unwrapping optional before initialized.#418
Merged
slavapestov merged 1 commit intoswiftlang:masterfrom Dec 11, 2015
Merged
[SR-184] Better diagnose error via unwrapping optional before initialized.#418slavapestov merged 1 commit intoswiftlang:masterfrom
slavapestov merged 1 commit intoswiftlang:masterfrom
Conversation
…zed. Added a check for whether the escape use is due to an UncheckedTakeEnumDataAddrInst, which accesses the memory to grab the .Some part of an Optional during “?.” or “!”. In that case, use the generic used-before-initialized diagnostic, since it isn’t actually because of closure capture. Added test cases, including specifically testing that capturing in a closure in order to unwrap the optional is still ok.
Contributor
Author
|
Tests pass! I initially thought that the last-resort else here might just be mistaken, and should be the generic used-before-initialized diagnostic instead, but that fails definite_init_diagnostics.swift:65 (capturing an Int to increment it before initialization). So added the more specific check for unchecked_take_enum_data_addr instead. |
Contributor
Author
|
Oh, and would be happy to add a more specific "optional unwrapped before initialized" diagnostic if that sounds like a good idea. The existing "used before being initialized" seems accurate, if inexact, and I think is quite clear enough. |
Contributor
|
@rudkx Looks good to me. |
slavapestov
added a commit
that referenced
this pull request
Dec 11, 2015
[SR-184] Better diagnose error via unwrapping optional before initialized.
Contributor
|
Nice! |
kateinoigakukun
pushed a commit
to kateinoigakukun/swift
that referenced
this pull request
Mar 20, 2020
[pull] swiftwasm from master
freak4pc
pushed a commit
to freak4pc/swift
that referenced
this pull request
Sep 28, 2022
Add Nimble to the test suite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added a check for whether the escape use is due to an UncheckedTakeEnumDataAddrInst, which accesses the memory to grab the .Some part of an Optional during “?.” or “!”. In that case, use the
generic used-before-initialized diagnostic, since it isn’t actually because of closure capture.
Added test cases, including specifically testing that capturing in a closure in order to unwrap the optional is still ok.